package com.jiyinit.web.core.activiti.dao;

import com.jiyinit.core.framework.dao.mybatis.base.MybatisDaoContext;
import com.jiyinit.web.core.activiti.entity.TabLeaveDealMindEntity;
import com.jiyinit.web.core.activiti.vo.NeedDealTaskEntity;
import com.jiyinit.web.core.common.util.Map2Bean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository("core.tabLeaveDealMindDao")
public class TabLeaveDealMindDao {

    /**
     * 日志对象
     */
    private static Logger logger = LoggerFactory.getLogger(TabLeaveDealMindDao.class);

    private String SQLID = "core.tabLeaveDealMindDao.";

    @Autowired
    @Qualifier("core.MybatisDaoContext")
    private MybatisDaoContext mybatisDaoContext;

    public int deleteByPrimaryKey(Integer id)
    {
        Map keyMap=new HashMap<>();
        keyMap.put("id",id);
        return mybatisDaoContext.delete(SQLID+"deleteByPrimaryKey",keyMap);
    }


    public int insert(TabLeaveDealMindEntity record)
    {
        return mybatisDaoContext.save(SQLID+"insert",record);
    }


    public int insertSelective(TabLeaveDealMindEntity record)
    {
        return mybatisDaoContext.save(SQLID+"insertSelective",record);
    }

    public TabLeaveDealMindEntity selectByPrimaryKey(Integer id)
    {
        Map keyMap=new HashMap<>();
        keyMap.put("id",id);
        return mybatisDaoContext.findOne(SQLID+"selectByPrimaryKey",TabLeaveDealMindEntity.class,keyMap);
    }

    public List<TabLeaveDealMindEntity> findBySelective(TabLeaveDealMindEntity record)
    {
        Map<String, Object> map= Map2Bean.beanToMap(record);
        return mybatisDaoContext.findAll(SQLID+"findBySelective",TabLeaveDealMindEntity.class,map);
    }

    public int updateByPrimaryKeySelective(TabLeaveDealMindEntity record)
    {
        return mybatisDaoContext.update(SQLID+"updateByPrimaryKeySelective",record);
    }

    public int updateByPrimaryKey(TabLeaveDealMindEntity record)
    {
        return mybatisDaoContext.update(SQLID+"updateByPrimaryKey",record);
    }

    /**
     * 查询已经处理过的任务(包含已同意和已拒绝的)
     * @param userId
     * @return
     */
    public List<NeedDealTaskEntity> getDealTasksByUserId(Integer userId){
        return mybatisDaoContext.findAll(SQLID+ "getDealTasksByUserId", userId);
    }
}